# 清华源镜像安装redis
# pip install --index-url https://pypi.tuna.tsinghua.edu.cn/simple redis

import redis
class Cache:
    def __init__(self,client):
        self.client = client

    def set(self,key,value):
        self.client.set(key,value)
    def get(self,key):
        return self.client.get(key)

    def update(self,key,new_value):
        return  self.client.getset(key,new_value)

if __name__=="__main__":
    # 使用文本编码的方式打开客户端
    r = redis.StrictRedis(host="127.0.0.1",port=6379,db = 0,decode_responses=True)
    r_cache= Cache(r)
    r.set("book",'code is magic')
    print(r.get("book"))
    r.getset("book","黄金时代")
    print(r.get("book"))

